package TestResult;


import jiazhong.Dao.EmpMapper;
import jiazhong.Dao.IUsersDao;
import jiazhong.pojo.Emp;
import jiazhong.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import tools.initLogRecord;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

//接口和sql分开
public class Test3 {

    private static InputStream in;
    private static SqlSessionFactory factory;
    private static SqlSession sqlSession;


    public static void init() throws IOException {
        //1.读取加载核心配置文件
        in = Resources.getResourceAsStream("config/mybatis-config.xml");
        //2.构造会话工厂
        factory = new SqlSessionFactoryBuilder().build(in);
        //3.创建对象会话
        sqlSession = factory.openSession();

    }


    @Test
    public void testFindById() throws IOException {
        //日志管理
        initLogRecord.initLog();
        init();

        EmpMapper map = sqlSession.getMapper(EmpMapper.class);
        Emp e = map.findById(3);
        System.out.println("e = " + e);
    }
    @Test
    public void testFindAll() throws IOException {
        //日志管理
        initLogRecord.initLog();
        init();

        EmpMapper map = sqlSession.getMapper(EmpMapper.class);
        List<Emp> all = map.findAll();
        for (Emp e:all){
            System.out.println("e = " + e);
        }
    }
}

